package com.robusta.cityuate.services;

import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;

import com.robusta.cityuate.utils.ConnectionUtils;

import android.content.Context;
import android.content.Intent;

public class SpotsListService extends HTTPService {

	@SuppressWarnings("unused")
	private static final String TAG = SpotsListService.class.getName();
	private final String REQUEST_URL = "/spots";
	private Context mContext = this;
	public static final String LIST_TYPE = "LIST_TYPE";
	public String spotsTypes[] = { "/all", "", "/favorites", "/near" };
	public static final String LATIT = "lat";
	public static final String LONGIT = "lng";
	public static final String RADUIS = "radius";

	@Override
	protected void onResponse() {
		Intent spotsListUIupdate = new Intent(assignedFilter);
		if (responseStatusCode == HttpStatus.SC_OK) {
			ConnectionUtils.setDisconnecting(mContext, true, assignedFilter,
					responseString);
			spotsListUIupdate.putExtra(RESUlT, true);
		}
		sendOrderedBroadcast(spotsListUIupdate, null);
	}

	@Override
	protected void onNoResponse(String msg) {
		// remove connection from shared pref keeping result and reason
		ConnectionUtils.setDisconnecting(mContext, false, assignedFilter, msg);
		// update UI if active
		Intent loginUIupdate = new Intent(assignedFilter);
		loginUIupdate.putExtra(RESUlT, false);
		sendOrderedBroadcast(loginUIupdate, null);

	}

	@Override
	protected HttpRequestBase initRequest() {
		if (extras.getInt(LIST_TYPE) == 3) {
			addPrameter(LATIT, "" + extras.getDouble(LATIT));
			addPrameter(LONGIT, "" + extras.getDouble(LONGIT));
			addPrameter(RADUIS, "" + extras.getDouble(RADUIS));
		}
		return new HttpGet(API_URL + REQUEST_URL
				+ spotsTypes[extras.getInt(LIST_TYPE)]);

	}

}
